<?php

namespace app\admin\controller\admin;

use app\admin\annotation\common\Auth;
use app\admin\controller\Admin;
use app\admin\model\admin\Dict as DictModel;
use app\admin\service\common\SortableService;
use app\admin\validate\admin\Config as ConfigValidate;
use app\admin\validate\admin\Dict as DictValidate;
use app\admin\service\admin\DictService;
use app\common\Constants;
use think\App;
use think\exception\ValidateException;
use think\facade\Log;

class Dict extends BaseDict
{

    public function __construct(
        App $app,
        protected DictModel  $dictModel,
        protected DictService $dictService
    )
    {
        parent::__construct($app,$dictModel);
    }

    /**
     * 加载数据字典到前端
     * @return \think\response\Json
     */
    public function getDictList(): \think\response\Json
    {
        $data = $this->dictModel->where(['status' => 1, 'type' => 1])->select()->toArray();;
        return $this->success(['data' => $data]);
    }

    /**
     * 通过代码获取字典数据
     *
     * @return \think\response\Json
     */
    public function getDictData(): \think\response\Json
    {
        $fields = "code,perms";
        $params = $this->request->only(explode(',', $fields), 'post');
        $data = $this->dictService->getDictData($params);
        return $this->success(['data' => $data]);
    }

}